package org.algorithm.Sort;

public class InsertSort {

    public static void insertSort(int [] array){
        int n =array.length;

        for (int i = 1; i <n; i++) {
            for (int j = i; j >0; j--) {
                if (array[j]<array[j-1]){
                    swap(array,j,j-1);
                }
            }
        }
    }

    public static void swap(int [] array,int index1,int index2){
        int temp  =array[index1];
        array[index1]=array[index2];
        array[index2]=temp;
    }

    public static void main(String[] args) {
        int [] array = {1,3,6,3,2,6,9};
        insertSort(array);
        for (int num:array) {
            System.out.println(num);
        }
    }
}

